import axios from 'axios'

const baseURL = 'http://localhost:40321/api'

// 创建 axios 实例
const request = axios.create({
  baseURL,
  withCredentials: true // 允许携带凭证
})

export const login = async (userAccount, userPassword) => {
  try {
    const response = await request.post('/user/login', {
      userAccount,
      userPassword
    })
    return response.data
  } catch (error) {
    throw error.response?.data || error
  }
}

export function logout(userId) {
  return request.post('/user/logout', { userId })
}

// 判断用户是否已登录
export const checkLoginStatus = async () => {
  try {
    const response = await request.post('/user/isLogin')
    return response.data
  } catch (error) {
    console.error('检查登录状态失败:', error)
    return { code: 500, data: false }
  }
} 